#include <iostream>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>




//./myfile > ok.txt 2>err.txt
//./myfile >ok.txt 2>&1 把错误消息和显示器文件上分别写入到不同的日志
int main()
{
    printf("hello printf 1\n");
    fprintf(stdout,"hello fprintf 1\n");

    perror("hello perror 2");

    const char* s1 = "hello write 1\n";
    write(1,s1,strlen(s1));

    const char* s2 = "hello write 2\n";
    write(2,s2,strlen(s2));

    std::cout<< "hello cout1\n" <<std::endl;
    std::cerr<< "hello cerr2\n" <<std::endl;

    //close(1);
    //int fd = open("log.txt",O_WRONLY | O_CREAT | O_TRUNC,0666);

    //if(fd < 0)
    //{
    //    perror("open");
    //    return 0;
    //}

    //printf("hello world [%d] \n",fd);//到显示器上
    //fflush(stdout);

    //const char* msg = "hello world\n";//到文件中
    //write(fd,msg,strlen(msg));

    //close(fd);
    return 0;
}

